//
//  GHRechargeViewController.m
//  GodHorses
//
//  Created by Mac on 2017/11/21.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "TMGRechageViewController.h"
#import "STRadioButton.h"
@interface TMGRechageViewController ()
@property(nonatomic, strong) STRadioButton                     *radioButton;
@property(nonatomic, strong) UITextField                       *moneyTextFiled;
@property(nonatomic, strong) STButton                     *oneButton;
@property(nonatomic, strong) STButton                     *secendButton;
@property(nonatomic, strong) STButton                     *thirdButton;
@end

@implementation TMGRechageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"充值";
    [self configSubView];
    [self configFotterView];
    [self addNotifacations];
    // Do any additional setup after loading the view.
}
#pragma mark --Notifacation
- (void)addNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textFieldTextDidChangeNotification:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:nil];
    
}
- (void)textFieldTextDidChangeNotification:(NSNotification*)nofia{
    if (nofia.object == self.moneyTextFiled) {
        NSString * text = self.moneyTextFiled.text;
        
        if ([text isEqualToString:@"500"]) {
            self.oneButton.selected = YES;
            self.secendButton.selected = NO;
            self.thirdButton.selected = NO;
        }
        if ([text isEqualToString:@"5000"]) {
            self.oneButton.selected = NO;
            self.secendButton.selected = YES;
            self.thirdButton.selected = NO;
        }
        if ([text isEqualToString:@"50000"]) {
            self.oneButton.selected = NO;
            self.secendButton.selected = NO;
            self.thirdButton.selected = YES;
        }
    }
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark --subView
- (void)configSubView{
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 200)];
    headerView.backgroundColor = self.tableView.backgroundColor;
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 30)
                                                     text:@"充值方式"
                                                textColor:FirstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:titleLable];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, titleLable.bottom, UIScreenWidth, 44)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:whiteView];
    
    self.radioButton = [[STRadioButton alloc] initWithRadio:@[@"银联充值"]
                                               andWithFrame:CGRectMake(0, 0, 85, 44)];
    self.radioButton.makenumOfarrayChecked = 0;
    self.radioButton.titleColor = FirstTextColor;
    [whiteView addSubview:self.radioButton];
    
    STButton * gouButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"PC_gouxuan__selected_red"]];
    gouButton.right = UIScreenWidth;
    gouButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [whiteView addSubview:gouButton];
    
    STLabel * moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(10, whiteView.bottom, UIScreenWidth - 20, 30)
                                                     text:@"充值金额"
                                                textColor:FirstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:moneyLable];
    
    UIView * moneywhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, moneyLable.bottom, UIScreenWidth, 44)];
    moneywhiteView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:moneywhiteView];
    
    self.moneyTextFiled = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 44)];
    self.moneyTextFiled.placeholder = @"请输入金额";
    self.moneyTextFiled.text = @"500";
    self.moneyTextFiled.textColor = FirstTextColor;
    self.moneyTextFiled.keyboardType = UIKeyboardTypeNumberPad;
    [moneywhiteView addSubview:self.moneyTextFiled];
    __weak typeof(self) weakSelf =  self;
    _oneButton = [[STButton alloc] initWithFrame:CGRectMake(10, moneywhiteView.bottom + 15, UIScreenWidth/3 - 20, 50)
                                           title:@"500元"
                                      titleColor:FirstTextColor
                                       titleFont:15
                                    cornerRadius:5
                                 backgroundColor:[UIColor whiteColor]
                                 backgroundImage:[UIImage imageNamed:@""]
                                           image:nil];
    [_oneButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [_oneButton setBackgroundImage:[UIImage imageNamed:@"gou"] forState:UIControlStateSelected];
    [_oneButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedMoneyButton:sender];
    }];
    _oneButton.selected = YES;
    [headerView addSubview:_oneButton];
    
    _secendButton = [[STButton alloc] initWithFrame:CGRectMake(_oneButton.right + 20, moneywhiteView.bottom + 15, UIScreenWidth/3 - 20, 50)
                                              title:@"5000元"
                                         titleColor:FirstTextColor
                                          titleFont:15
                                       cornerRadius:5
                                    backgroundColor:[UIColor whiteColor]
                                    backgroundImage:[UIImage imageNamed:@""]
                                              image:nil];
    [_secendButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [_secendButton setBackgroundImage:[UIImage imageNamed:@"gou"] forState:UIControlStateSelected];
    [_secendButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedMoneyButton:sender];
    }];
    [headerView addSubview:_secendButton];
    
    _thirdButton = [[STButton alloc] initWithFrame:CGRectMake(_secendButton.right + 20, moneywhiteView.bottom + 15, UIScreenWidth/3 - 20, 50)
                                             title:@"50000元"
                                        titleColor:FirstTextColor
                                         titleFont:15
                                      cornerRadius:5
                                   backgroundColor:[UIColor whiteColor]
                                   backgroundImage:[UIImage imageNamed:@""]
                                             image:nil];
    [_thirdButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [_thirdButton setBackgroundImage:[UIImage imageNamed:@"gou"] forState:UIControlStateSelected];
    [_thirdButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedMoneyButton:sender];
    }];
    [headerView addSubview:_thirdButton];
    
    
    headerView.height = _thirdButton.bottom + 10;
    self.tableView.tableHeaderView = headerView;
}
- (void)configFotterView{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, 0, UIScreenWidth - 60, 44)
                                                        title:@"确认充值"
                                                   titleColor:[UIColor whiteColor]
                                                    titleFont:18
                                                 cornerRadius:5
                                              backgroundColor:TM_orangeColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedCommitButton];
    }];
    confimButton.st_centerY = 50;
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    
    STButton * lineButton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30, 44)
                                                      title:@"大额充值请到官方网站"
                                                 titleColor:FirstTextColor
                                                  titleFont:18
                                               cornerRadius:5
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:nil];
    [lineButton setClicAction:^(UIButton *sender) {
       // [weakSelf onSelectedLineButton];
    }];
    lineButton.top = confimButton.bottom + 20;
    [footer addSubview:lineButton];
    
    footer.height = lineButton.bottom + 20;
    
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSlectedMoneyButton:(UIButton*)sender{
    self.oneButton.selected = NO;
    self.thirdButton.selected = NO;
    self.secendButton.selected = NO;
    sender.selected = YES;
    NSString * money = [sender.currentTitle stringByReplacingOccurrencesOfString:@"元" withString:@""];
    self.moneyTextFiled.text = money;
}
- (void)onSelectedCommitButton{
    [self sendFetchsignRequest];
}
- (void)onSelectedLineButton{

}
- (void)sendFetchsignRequest{

}

@end

